<?php
$name ='11028777';
$pass = '03150';
// $cookie_jar = ('/tmp/wlyc_cookie');
$cookie_jar = ('D:/xampp/htdocs/wlyc/tmp/wlyc_cookie');
$options = array(
    CURLOPT_URL => 'http://114.251.109.215/wlyc/',
    CURLOPT_COOKIEJAR => $cookie_jar,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HEADER => false,
    CURLOPT_FAILONERROR => true,
    CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9',
);

if(file_exists($cookie_jar)) unlink($cookie_jar);
login($name,$pass,$cookie_jar,$options);
$result = request(array(CURLOPT_URL=>'http://114.251.109.215/wlyc/aspx/car/XYYC22.aspx',CURLOPT_COOKIEFILE=>$cookie_jar)+$options);
echo str_replace('<head>','<head><base href="http://114.251.109.215/wlyc/aspx/car/" />',$result['response']);

function request($args){
    $ch = curl_init();
    curl_setopt_array($ch, $args);
    $return = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    while($return === false){
        // exit(curl_error($ch));
        return request($args);
    }
    return array('response' => $return, 'info' => $info);
}

function login($name,$pass,$cookie_jar,$options){
    $return = request($options);
    preg_match('#__VIEWSTATE" value="(.*?)" />#iU',$return['response'],$vs);
    preg_match('#__EVENTVALIDATION" value="(.*?)" />#iU',$return['response'],$ev);
    request(array(CURLOPT_URL => 'http://114.251.109.215/wlyc/image.aspx')+$options);
    $captcha = (trim(array_pop(explode("\t",array_pop(file($cookie_jar))))));
    $request = '__EVENTVALIDATION='.urlencode($ev[1]).'&__VIEWSTATE='.urlencode($vs[1])."&txtname={$name}&txtpwd={$pass}&yanzheng=".trim($captcha).'&button.x=18&button.y=15';
    request(array(CURLOPT_URL=>'http://114.251.109.215/wlyc/XYYC21DR1.aspx',CURLOPT_POST=>true,CURLOPT_COOKIEFILE=>$cookie_jar,CURLOPT_POSTFIELDS=>$request)+$options);
}
